import pickle

def test_list(num):
    return [i for i in range(num) if i % 2 == 0]

if __name__ == '__main__':
    mylist = test_list(100)
    try:
        with open('pickle_test.txt', 'wb') as testfile:
            pickle.dump(mylist, testfile)
        print 'writelist is ', mylist
        print 'pickle dump end'
        readlist = []
        with open('pickle_test.txt', 'rb') as testfile:
           readlist =  pickle.load(testfile)
        print 'read list is ', readlist 
    except IOError as err:
        print 'exception is ' + str(err)
